import FlagController, { FlagPrefix } from '@/modules/flag'
import BattleSpawn from './spawn'
import BattleCore from './core'

/**
 * 战斗管理
 */
export default class BattleManager {
    public static run() {
        const flags = FlagController.getFlagsByPrefix(FlagPrefix.team)
        const continueFlags = FlagController.getFlagsByPrefix(FlagPrefix.teamContinue)
        const battleFlags = BattleSpawn.getAvailableFlags(flags)

        battleFlags.forEach((flag) => {
            // 没孵化齐或者寿命没对齐
            if (!BattleSpawn.spawnCreeps(flag) || !BattleSpawn.renewCreeps(flag)) return
            // 等待 boost 完成
            if (!BattleSpawn.waitForBoost(flag)) return
            // 执行小队任务
            BattleCore.exec(flag)
        })

        BattleSpawn.continueSpawn(continueFlags)
    }
}
